package angry.courses.listeners;

import angry.courses.database.CoursesDBReal;
import angry.courses.database.ICoursesDB;
import angry.courses.database.CoursesDBMock;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;

public final class ContextListener implements ServletContextListener {

    public void contextInitialized(ServletContextEvent event) {
	ServletContext context = event.getServletContext();

	//ICoursesDB coursesDB = new CoursesDBMock();
	ICoursesDB coursesDB = new CoursesDBReal();
	context.setAttribute("coursesDB", coursesDB);
    }

    public void contextDestroyed(ServletContextEvent event) {
	ServletContext context = event.getServletContext();
	
	context.removeAttribute("coursesDB");
    }
}
